package com.hs.gs.web;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hs.gs.domain.Checking;

@RooWebScaffold(path = "checkings", formBackingObject = Checking.class)
@RequestMapping("/checkings")
@Controller
public class CheckingController {

    @RequestMapping(method = RequestMethod.POST)
    public String create(@Valid Checking checking, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
        if (bindingResult.hasErrors()) {
            uiModel.addAttribute("checking", checking);
            addDateTimeFormatPatterns(uiModel);
            return "checkings/create";
        }
        uiModel.asMap().clear();
        checking.setCheckingTime(new Date());
        checking.persist();
        return "redirect:/checkings/" + encodeUrlPathSegment(checking.getId().toString(), httpServletRequest);
    }
}
